package top.api.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import top.api.common.ResUlt;
import top.api.domain.dto.PageDto;
import top.api.domain.pojo.Class;
import top.api.domain.pojo.User;
import top.api.service.ClassService;
import top.api.service.impl.ClassServiceImpl;

import java.util.List;

@RestController
@RequestMapping("/class")
@RequiredArgsConstructor
public class ClassController {

    private final ClassServiceImpl classService;
    @GetMapping("/list")
//    @SaCheckRole("admin")
    @ApiOperation("分页查询")
    public ResUlt<?> listPage(PageDto pageDto, Integer id, String classname){
        return classService.listPage(pageDto,id,classname);
    }


    @PostMapping
    @SaCheckRole("admin")
    @ApiOperation("添加班级")
    public ResUlt<?> add(@RequestBody Class c){
        return classService.add(c);
    }


    @GetMapping("{id}")
    @ApiOperation("查询班级")
    public ResUlt<?> getOne(@PathVariable Integer id){
        return classService.getOne(id);
    }

    @DeleteMapping("{id}")
    @SaCheckRole("admin")
    @ApiOperation("删除班级")
    public ResUlt<?> delete(@PathVariable List id){
        return classService.delete(id);
    }

    @PutMapping
    @SaCheckRole("admin")
    @ApiOperation("更新班级")
    public ResUlt<?> updateUser(@RequestBody Class c){
        return classService.changeClass(c);
    }

    @PutMapping("/status")
    @SaCheckRole("admin")
    @ApiOperation("账号封禁")
    public ResUlt<?> changeStatus(@RequestBody Class c){
        return classService.changeStatus(c);
    }

}
